--Generated Upgrade For Version 0.0.0.0.22
--Generated on 2013-03-15 19:38:04

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__PRODUCT_CATEGORY' and xtype = 'F')
ALTER TABLE [dbo].[Product] DROP CONSTRAINT [FK__PRODUCT_CATEGORY]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__ORDER_CUSTOMER' and xtype = 'F')
ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK__ORDER_CUSTOMER]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__EMPLOYEETERRITORY_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[EmployeeTerritory] DROP CONSTRAINT [FK__EMPLOYEETERRITORY_EMPLOYEE]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__ORDER_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK__ORDER_EMPLOYEE]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK_REPORTSTO_EMPLOYEE_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[Employee] DROP CONSTRAINT [FK_REPORTSTO_EMPLOYEE_EMPLOYEE]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__ORDERDETAIL_ORDER' and xtype = 'F')
ALTER TABLE [dbo].[OrderDetail] DROP CONSTRAINT [FK__ORDERDETAIL_ORDER]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__ORDERDETAIL_PRODUCT' and xtype = 'F')
ALTER TABLE [dbo].[OrderDetail] DROP CONSTRAINT [FK__ORDERDETAIL_PRODUCT]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__TERRITORY_REGION' and xtype = 'F')
ALTER TABLE [dbo].[Territory] DROP CONSTRAINT [FK__TERRITORY_REGION]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__ORDER_SHIPPER' and xtype = 'F')
ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK__ORDER_SHIPPER]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__PRODUCT_SUPPLIER' and xtype = 'F')
ALTER TABLE [dbo].[Product] DROP CONSTRAINT [FK__PRODUCT_SUPPLIER]
GO

--REMOVE FOREIGN KEY
if exists(select * from sysobjects where name = 'FK__EMPLOYEETERRITORY_TERRITORY' and xtype = 'F')
ALTER TABLE [dbo].[EmployeeTerritory] DROP CONSTRAINT [FK__EMPLOYEETERRITORY_TERRITORY]
GO

--FOREIGN KEY RELATIONSHIP [Category] -> [Product] ([Category].[CategoryId] -> [Product].[CategoryId])
if not exists(select * from sysobjects where name = 'FK__PRODUCT_CATEGORY' and xtype = 'F')
ALTER TABLE [dbo].[Product] ADD 
CONSTRAINT [FK__PRODUCT_CATEGORY] FOREIGN KEY 
(
	[CategoryId]
) REFERENCES [dbo].[Category] (
	[CategoryId]
)
GO

--FOREIGN KEY RELATIONSHIP [Customer] -> [Order] ([Customer].[UserId] -> [Order].[UserId])
if not exists(select * from sysobjects where name = 'FK__ORDER_CUSTOMER' and xtype = 'F')
ALTER TABLE [dbo].[Order] ADD 
CONSTRAINT [FK__ORDER_CUSTOMER] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[Customer] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Employee] -> [EmployeeTerritory] ([Employee].[UserId] -> [EmployeeTerritory].[UserId])
if not exists(select * from sysobjects where name = 'FK__EMPLOYEETERRITORY_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[EmployeeTerritory] ADD 
CONSTRAINT [FK__EMPLOYEETERRITORY_EMPLOYEE] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[Employee] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Employee] -> [Order] ([Employee].[UserId] -> [Order].[EmployeeId])
if not exists(select * from sysobjects where name = 'FK__ORDER_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[Order] ADD 
CONSTRAINT [FK__ORDER_EMPLOYEE] FOREIGN KEY 
(
	[EmployeeId]
) REFERENCES [dbo].[Employee] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Employee] -> [Employee] ([Employee].[UserId] -> [Employee].[ReportsTo])
if not exists(select * from sysobjects where name = 'FK_REPORTSTO_EMPLOYEE_EMPLOYEE' and xtype = 'F')
ALTER TABLE [dbo].[Employee] ADD 
CONSTRAINT [FK_REPORTSTO_EMPLOYEE_EMPLOYEE] FOREIGN KEY 
(
	[ReportsTo]
) REFERENCES [dbo].[Employee] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Order] -> [OrderDetail] ([Order].[OrderId] -> [OrderDetail].[OrderId])
if not exists(select * from sysobjects where name = 'FK__ORDERDETAIL_ORDER' and xtype = 'F')
ALTER TABLE [dbo].[OrderDetail] ADD 
CONSTRAINT [FK__ORDERDETAIL_ORDER] FOREIGN KEY 
(
	[OrderId]
) REFERENCES [dbo].[Order] (
	[OrderId]
)
GO

--FOREIGN KEY RELATIONSHIP [Product] -> [OrderDetail] ([Product].[ProductId] -> [OrderDetail].[ProductId])
if not exists(select * from sysobjects where name = 'FK__ORDERDETAIL_PRODUCT' and xtype = 'F')
ALTER TABLE [dbo].[OrderDetail] ADD 
CONSTRAINT [FK__ORDERDETAIL_PRODUCT] FOREIGN KEY 
(
	[ProductId]
) REFERENCES [dbo].[Product] (
	[ProductId]
)
GO

--FOREIGN KEY RELATIONSHIP [Region] -> [Territory] ([Region].[RegionId] -> [Territory].[RegionId])
if not exists(select * from sysobjects where name = 'FK__TERRITORY_REGION' and xtype = 'F')
ALTER TABLE [dbo].[Territory] ADD 
CONSTRAINT [FK__TERRITORY_REGION] FOREIGN KEY 
(
	[RegionId]
) REFERENCES [dbo].[Region] (
	[RegionId]
)
GO

--FOREIGN KEY RELATIONSHIP [Shipper] -> [Order] ([Shipper].[ShipperId] -> [Order].[ShipperId])
if not exists(select * from sysobjects where name = 'FK__ORDER_SHIPPER' and xtype = 'F')
ALTER TABLE [dbo].[Order] ADD 
CONSTRAINT [FK__ORDER_SHIPPER] FOREIGN KEY 
(
	[ShipperId]
) REFERENCES [dbo].[Shipper] (
	[ShipperId]
)
GO

--FOREIGN KEY RELATIONSHIP [Supplier] -> [Product] ([Supplier].[UserId] -> [Product].[SupplierId])
if not exists(select * from sysobjects where name = 'FK__PRODUCT_SUPPLIER' and xtype = 'F')
ALTER TABLE [dbo].[Product] ADD 
CONSTRAINT [FK__PRODUCT_SUPPLIER] FOREIGN KEY 
(
	[SupplierId]
) REFERENCES [dbo].[Supplier] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Territory] -> [EmployeeTerritory] ([Territory].[TerritoryId] -> [EmployeeTerritory].[TerritoryId])
if not exists(select * from sysobjects where name = 'FK__EMPLOYEETERRITORY_TERRITORY' and xtype = 'F')
ALTER TABLE [dbo].[EmployeeTerritory] ADD 
CONSTRAINT [FK__EMPLOYEETERRITORY_TERRITORY] FOREIGN KEY 
(
	[TerritoryId]
) REFERENCES [dbo].[Territory] (
	[TerritoryId]
)
GO

